import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2024-06-06
 * Time: 16:56
 */
public class Solution {
    public String largestNumber(int[] nums) {
        //把数转化成字符串比较字典序
        int n = nums.length;
        String[] strings = new String[n];

        for (int i = 0; i < n; i++) {
            strings[i] = "" + nums[i];
        }

        Arrays.sort(strings,(a,b)->{

            return (b+a).compareTo(a+b);
        });

        StringBuilder stringBuffer = new StringBuilder();
        for (int i = 0; i < n; i++) {
            stringBuffer.append(strings[i]);
        }

        if(stringBuffer.charAt(0) == '0'){
            return "0";
        }
        return stringBuffer.toString();

    }
}
